package com.my.radio;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class RadioSharedPreferences {
	public static String KEY_FAVORITE_FM = "favorite_fm";
	public static String KEY_FAVORITE_AM = "favorite_am";
	public static String KEY_LIST_FM = "list_fm";
	public static String KEY_LIST_AM = "list_am";
	
	private static SharedPreferences mPreferences;
	
	public static SharedPreferences getPreferences(Context context){
		if (mPreferences == null)
			mPreferences = PreferenceManager
					.getDefaultSharedPreferences(context);
		return mPreferences;
	}
	
	public static void initPreferences(Context context){
		getPreferences(context);
		mPreferences.edit().putString(KEY_FAVORITE_FM, "").commit();
		mPreferences.edit().putString(KEY_FAVORITE_AM, "").commit();
	}

	public static String getString(Context context, String key) {
		getPreferences(context);
		return mPreferences.getString(key, "");
	}
	
	public static String getString(Context context, String key, String defValue) {
		getPreferences(context);
		return mPreferences.getString(key, defValue);
	}

	public static boolean putString(Context context, String key, String value) {
		getPreferences(context);
		return mPreferences.edit().putString(key, value).commit();
	}

	public static int getInt(Context context, String key, int defValue) {
		getPreferences(context);
		return mPreferences.getInt(key, defValue);
	}
	
	public static boolean putInt(Context context, String key, int value) {
		getPreferences(context);
		return mPreferences.edit().putInt(key, value).commit();
	}
	
	public static long getLong(Context context, String key, long defValue) {
		getPreferences(context);
		return mPreferences.getLong(key, defValue);
	}
	
	public static boolean putLong(Context context, String key, long value) {
		getPreferences(context);
		return mPreferences.edit().putLong(key, value).commit();
	}

	public static boolean getBoolean(Context context, String key, boolean defValue) {
		getPreferences(context);
		return mPreferences.getBoolean(key, defValue);
	}
	
	public static boolean putBoolean(Context context, String key, boolean value) {
		getPreferences(context);
		return mPreferences.edit().putBoolean(key, value).commit();
	}

	public static boolean clear(Context context) {
		getPreferences(context);
		return mPreferences.edit().clear().commit();
	}
}